package cn.iocoder.yudao.framework.business.eligibility.pojo.vo;

import cn.iocoder.yudao.framework.business.basic.pojo.vo.MemberScopeVO;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.time.LocalDateTime;

@Data
public class EligibilityUserVO extends MemberScopeVO {

    @Schema(description = "累计购买金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "25735")
    private Integer cumulativePrice;

    @Schema(description = "累计购买次数", requiredMode = Schema.RequiredMode.REQUIRED, example = "17693")
    private Integer purchaseCount;

    public Integer getPurchaseCount() {
        if (purchaseCount == null) {
            purchaseCount = 0;
        }
        return purchaseCount;
    }

    @Schema(description = "累计购买天数", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
    private Integer daysCount;

    @Schema(description = "最近购买天数", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
    private Integer lastDays;

    @Schema(description = "到期时间", requiredMode = Schema.RequiredMode.REQUIRED)
    private LocalDateTime expireTime;

    public LocalDateTime getExpireTime() {
        if (expireTime == null) {
            expireTime = LocalDateTime.now();
        }
        return expireTime;
    }

    @Schema(description = "是否有效", requiredMode = Schema.RequiredMode.REQUIRED, example = "true")
    private boolean valid;

    @SuppressWarnings("unused")
    public boolean isValid() {
        return getPurchaseCount() > 0 && getExpireTime().isAfter(LocalDateTime.now());
    }

}